package com.simba.system.service.impl;

import com.simba.system.entity.Menu;
import com.simba.system.entity.User;
import com.simba.system.mapper.MenuMapper;
import com.simba.system.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜单权限表 服务实现类
 * </p>
 *
 * @author 陈俊 1002471284@qq.com
 * @since 2021-03-24
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<Menu> getMenusByUserId() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return menuMapper.getMenusByUserId(user.getUserId());
    }

    @Override
    public List<Menu> getMenusWithRole() {
        return menuMapper.getMenusWithRole();
    }

    @Override
    public List<Menu> getMenusWithRoleByUrl(String url) {
        return menuMapper.getMenusWithRoleByUrl(url);
    }
}
